# ALSA 音频播放程序 Makefile

# 编译器设置
CC = gcc
CFLAGS = -Wall -Werror -g

# ALSA 库设置
# 默认使用系统标准路径的ALSA库
ALSA_LIBS = -lasound

# 如果ALSA库安装在非标准路径，可以取消下面的注释并修改路径
# ALSA_INCLUDE = -I/usr/local/alsa/include
# ALSA_LIBPATH = -L/usr/local/alsa/lib
# ALSA_LIBS = -lasound

# 合并编译选项
ifeq ($(ALSA_INCLUDE),)
    COMPILE_FLAGS = $(CFLAGS)
else
    COMPILE_FLAGS = $(CFLAGS) $(ALSA_INCLUDE)
endif

# 合并链接选项
ifeq ($(ALSA_LIBPATH),)
    LINK_FLAGS = $(ALSA_LIBS)
else
    LINK_FLAGS = $(ALSA_LIBPATH) $(ALSA_LIBS)
endif

# 目标和依赖
TARGET = play_raw
SRCS = play_raw.c
OBJS = $(SRCS:.c=.o)

# 默认目标
all: $(TARGET)

# 链接目标
$(TARGET): $(OBJS)
	$(CC) -o $@ $^ $(LINK_FLAGS)

# 编译源文件
%.o: %.c
	$(CC) -c -o $@ $< $(COMPILE_FLAGS)

# 清理目标
clean:
	rm -f $(TARGET) $(OBJS)

# 安装目标（可选）
install:
	mkdir -p $(DESTDIR)/usr/local/bin
	cp $(TARGET) $(DESTDIR)/usr/local/bin

# 帮助信息
help:
	@echo "ALSA 音频播放程序 Makefile"
	@echo "用法:"
	@echo "  make            - 编译程序"
	@echo "  make clean      - 清理编译文件"
	@echo "  make install    - 安装程序（需要root权限）"
	@echo "  make help       - 显示此帮助信息"
	@echo "\n配置选项:"
	@echo "  如果ALSA库安装在非标准路径，修改Makefile中的ALSA_INCLUDE和ALSA_LIBPATH变量"

.PHONY: all clean install help